package com.kaizeli.website.controller;

import com.kaizeli.website.pojo.vo.ProjectStatisticsVO;
import com.kaizeli.website.response.Result;
import com.kaizeli.website.service.ProjectStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 项目统计Controller
 */
@RestController
@RequestMapping("/api/project-statistics")
@CrossOrigin(origins = "*")
public class ProjectStatisticsController {
    
    @Autowired
    private ProjectStatisticsService projectStatisticsService;
    
    /**
     * 根据项目编号获取项目统计数据
     */
    @GetMapping("/project-code/{projectCode}")
    public Result<ProjectStatisticsVO> getProjectStatisticsByCode(@PathVariable String projectCode) {
        try {
            ProjectStatisticsVO statistics = projectStatisticsService.getProjectStatisticsByCode(projectCode);
            if (statistics == null) {
                return Result.error(404, "项目不存在");
            }
            return Result.success(statistics);
        } catch (Exception e) {
            return Result.error(500, "获取项目统计数据失败: " + e.getMessage());
        }
    }
    
    /**
     * 根据项目ID获取项目统计数据
     */
    @GetMapping("/project/{projectId}")
    public Result<ProjectStatisticsVO> getProjectStatisticsById(@PathVariable Long projectId) {
        try {
            ProjectStatisticsVO statistics = projectStatisticsService.getProjectStatisticsById(projectId);
            if (statistics == null) {
                return Result.error(404, "项目不存在");
            }
            return Result.success(statistics);
        } catch (Exception e) {
            return Result.error(500, "获取项目统计数据失败: " + e.getMessage());
        }
    }
}
